package setting

import "gopkg.in/ini.v1"

var Conf = new(AppConfig)

var Channels = map[string]bool{
	"__all__":            true,
	"news_hot":           true,
	"news_society":       true,
	"news_entertainment": true,
	"news_tech":          true,
	"news_military":      true,
	"news_sports":        true,
	"news_car":           true,
	"news_food":          true,
}

// AppConfig 应用程序配置
type AppConfig struct {
	Release             bool   `ini:"release"`
	Port                int    `ini:"port"`
	Register            bool   `ini:"register"`
	ApiDomain           string `ini:"api_domain"`
	AppDomain           string `ini:"app_domain"`
	CDNDomain           string `ini:"cdn_domain"`
	ReportServiceDomain string `ini:"report_service"`
	*MySQLConfig        `ini:"mysql"`
	*SMTPConfig         `ini:"smtp"`
	*RedisConfig        `ini:"redis"`
	*UpYunConfig        `ini:"upyun"`
	*MongoDBConfig      `ini:"mongo"`
}

// MySQLConfig 数据库配置
type MySQLConfig struct {
	User     string `ini:"user"`
	Password string `ini:"password"`
	DB       string `ini:"db"`
	Host     string `ini:"host"`
	Port     int    `ini:"port"`
}

type SMTPConfig struct {
	MailHost     string `ini:"mail_host"`
	MailPort     string `ini:"mail_port"`
	MailUser     string `ini:"mail_user"`
	MailPwd      string `ini:"mail_pwd"`
	MailNickName string `ini:"mail_nickname"`
}

type RedisConfig struct {
	RedisHost string `ini:"redis_host"`
	RedisPort string `ini:"redis_port"`
}

type UpYunConfig struct {
	Bucket   string `ini:"bucket"`
	Operator string `ini:"operator"`
	Password string `ini:"password"`
}

type MongoDBConfig struct {
	Host     string `ini:"host"`
	Port     string `ini:"port"`
	Database string `ini:"database"`
}

// Init 加载配置文件
func Init(file string) error {
	return ini.MapTo(Conf, file)
}
